{extend name="public/base" /}

{block name="content"}

<div class="layui-card">

    <!-- <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">文章ID/标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="so" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">文章标签</label>
                <div class="layui-input-inline">
                    <select name="classId">
                        <option value="">请选择标签</option>
                        <option value="0">美食</option>
                        <option value="1">新闻</option>
                        <option value="2">八卦</option>
                        <option value="3">体育</option>
                        <option value="4">音乐</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-projects-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
    </div> -->

    <div class="layui-card-body">
        <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
    </div>
</div>

<form id="form" class="layui-form" style="display: none" lay-filter="form">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">类型名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>
</form>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
        <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
    </div>
</script>

<script type="text/html" id="table-content-list">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script type="text/html" id="imgTpl">
    <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.img }}>
</script>
{/block}

{block name='js'}
<script>
    layui.use(['table'], function () {
        let $ = layui.$,
            table = layui.table,
            form = layui.form,
            TableData = table.render({
                elem: '#LAY-app-content-list'
                , toolbar: '#toolbarDemo'
                , page: true
                , method: 'post'
                , limit: 15
                , limits: [15, 50, 200, 600, 1000, 1800, 3000]
                , url: '/manage/projects/video/classify/list' //数据接口
                , title: '类型表'
                , cols: [
                    [ //表头
                        {field: 'id', type: 'checkbox', align: 'center'}
                        , {field: 'id', title: 'ID', align: 'center'}
                        , {field: 'name', title: '名称', align: 'center'}
                        , {field: 'createTime', title: '创建时间', align: 'center'}
                        , {fixed: 'right', title: '操作', toolbar: '#table-content-list', width: 150}
                    ]
                ]
            })

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            let field = data.field;
            //执行重载
            table.reload('LAY-app-content-list', {
                where: field
            });
        });

        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-app-content-list')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.confirm('确定删除吗？', function (index) {

                    //执行 Ajax 后重载
                    /*
                    admin.req({
                      url: 'xxx'
                      //,……
                    });
                    */
                    table.reload('LAY-app-content-list');
                    layer.msg('已删除');
                });
            },
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            let type = $(this).data('type');
            switch (type) {
                case 'add':
                    layer.open({
                        type: 1,
                        title: '添加分类',
                        content: $('#form'),
                        area: ['550px', '550px'],
                        btn: ['确定', '取消'],
                        btn1: function (index, layero) {
                            let data = $('#form').serializeArray();
                            $.ajax({
                                method: 'post',
                                data: data,
                                dataType: 'json',
                                url: '/manage/video/addClassify',
                                success: function (res) {
                                    if (res.code !== 0) {
                                        layer.msg(res.message);
                                    } else {
                                        layer.msg('添加成功');
                                        layer.close(index);
                                        table.reload(TableData);
                                        table.reload('LAY-app-content-list');
                                    }
                                },
                                error: function (res) {

                                }
                            })
                        }
                    });
                    break;
            }
        });

    });
</script>
{/block}